package com.itheima.demo1;

import java.util.TreeMap;

public class TreeMapDemo2 {
    public static void main(String[] args) {
        String s = "avaszdfasnkjfsad";

        TreeMap<Character, Integer> tm = new TreeMap<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            //判断当前值是否在集合中存在
            if (tm.containsKey(c)){
                Integer count = tm.get(c);
                count++;
                tm.put(c,count);
            }else {
                tm.put(c,1);
            }
        }


//        System.out.println(tm);
        StringBuilder sb = new StringBuilder();

        tm.forEach((key,value) -> sb.append(key).append("(").append(value).append(")") );

        System.out.println(sb.toString());


    }
}
